using System.Collections.Generic;
using I2.Loc;
using UnityEngine;

public class LocalizeFontSetter : MonoBehaviour
{
	private static Dictionary<string, Font> _defaultTtf;

	private static Dictionary<string, string> _fontConfig;

	private UILabel _targetLable;

	private UIFont _defaultFont;

	public static Dictionary<string, string> GetFontConfig()
	{
		if (_fontConfig == null)
		{
			_fontConfig = new Dictionary<string, string>();
			_fontConfig.Add("Chinese", "Fonts/chinese");
			_fontConfig.Add("Japanese", "Fonts/ArialFont");
			_fontConfig.Add("Korean", "Fonts/ArialFont");
			_fontConfig.Add("Spanish", "Fonts/ArialFont");
			_fontConfig.Add("German", "Fonts/ArialFont");
			_fontConfig.Add("French", "Fonts/ArialFont");
		}
		return _fontConfig;
	}

	private void Awake()
	{
		_targetLable = base.gameObject.GetComponent<UILabel>();
		_defaultFont = _targetLable.bitmapFont;
		InitDefaultTTF();
	}

	private void OnEnable()
	{
		ChangeFont();
		SwitchLanguage.onChangeLanguage += ChangeFont;
	}

	private void OnDisable()
	{
		SwitchLanguage.onChangeLanguage -= ChangeFont;
	}

	private void InitDefaultTTF()
	{
		if (_defaultTtf != null)
		{
			return;
		}
		_defaultTtf = new Dictionary<string, Font>();
		foreach (KeyValuePair<string, string> item in GetFontConfig())
		{
			_defaultTtf.Add(item.Key, Resources.Load(item.Value) as Font);
		}
	}

	public void ChangeFont()
	{
		if (!(_targetLable == null))
		{
			if (_defaultTtf.ContainsKey(LocalizationManager.CurrentLanguage))
			{
				_targetLable.trueTypeFont = _defaultTtf[LocalizationManager.CurrentLanguage];
			}
			else
			{
				_targetLable.bitmapFont = _defaultFont;
			}
		}
	}
}
